<template>
  <s-modal
    title="修改"
    :visible="visible"
    width="800px"
    ok-text="保存"
    :confirm-loading="confirmLoading"
    :closable="!confirmLoading"
    @ok="save()"
    @cancel="()=>{if(!confirmLoading){ visible=false }}"
  >
    <div style="height:400px">
      <s-scroll>
        <s-form ref="form" :value="formValue">
          <s-form-item
            label="标题"
            size="big"
            name="title"
            :colon="true"
            :display-title="true"
            :rules="[{'whitespace':true,'required':true,'message':'标题不能为空'},{'max':255,'message':'最长为255位'}]"
          >
            <s-input
              :allow-clear="true"
              placeholder="请输入标题"
              v-model="formValue.title"
              />
          </s-form-item>
          <s-form-item
            label="知识库分类"
            size="big"
            name="typeNo"
            :colon="true"
            :display-title="true"
            :rules="[{'whitespace':true,'required':true,'message':'知识库分类不能为空'}]"
          >
            <s-select
              :allow-clear="true"
              placeholder="请选择知识库分类"
              :show-search="true"
              code="INFOMATION"
              v-model="formValue.typeNo"
              />
          </s-form-item>
          <s-form-item
            label="资料权限"
            size="big"
            name="authType"
            :colon="true"
            :display-title="true"
            :rules="[{'whitespace':true,'required':true,'message':'资料权限不能为空'}]"
          >
            <s-select
              :allow-clear="true"
              placeholder="请选择资料权限"
              :show-search="true"
              code="AUTH_TYPE"
              v-model="formValue.authType"
              />
          </s-form-item>
          <s-form-item
            v-if="formValue.authType=='2'"
            label="推送单位"
            size="big"
            name="pushUnit"
            :colon="true"
            :display-title="true"
          >
            <s-select-tree
              :allow-clear="true"
              placeholder="请选择推送单位"
              :expand-all="false"
              :show-search="true"
              :multiple="true"
              url="/realm/dept/selectList"
              label-field="text"
              value-field="id"
              key-field="id"
              parent-key-field="parentId"
              v-model="formValue.pushUnit"
              />
          </s-form-item>
          <s-form-item
            label="附件地址"
            size="big"
            name="annex"
            :colon="true"
            :display-title="true"
          >
            <s-file
              :allow-clear="true"
              v-model="formValue.annex"
              />
          </s-form-item>
          <s-form-item
            label="内容"
            size="big"
            name="content"
            :colon="true"
            :display-title="true"
            :rules="[{'whitespace':true,'required':true,'message':'内容不能为空'},{'max':65535,'message':'最长为65535位'}]"
          >
            <s-text-area
              :allow-clear="true"
              placeholder="请输入内容"
              :rowNum="20"
              v-model="formValue.content"
              />
          </s-form-item>

        </s-form>
      </s-scroll>
    </div>
  </s-modal>
</template>

<script>

export default {
  name: 'Update',
  emits: ['change'],
  data() {
    return {
      formValue: {},
      confirmLoading: false,
      visible: false
    }
  },
  methods: {
    open(id) {
      this.formValue = {}
      this.$loading(true)
      this.$api.GET('/modules/infomation/selectOneById', { id: id }).then(res => {
        if (!res.data) {
          this.$loading(false)
          this.visible = false
          this.$message.warn('数据不存在')
        } else {
          this.formValue = res.data
          this.$loading(false)
          this.visible = true
        }
      }).catch(() => {
        this.$loading(false)
      })
    },
    save() {
	  const _this=this
      const form = this.$refs.form
      form.validate((values,fullValue) => {
	    
        this.confirmLoading = true
        values.id = this.formValue.id
        this.$api.PUT('/modules/infomation/update', values).then(res => {
          this.confirmLoading = false
          this.visible = false
          this.$emit('success');
          this.$message.info(res.msg)
        }).catch(() => {
          this.confirmLoading = false
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>